<template>
  <div class="aui-card-list">
    <uni-list-query-card :queryShow="queryShow" @query-click="getDataList()" @click="(e)=>{this.queryShow=e}"
      @searchReset="searchReset()">
      <el-col :span="6">
        <el-form-item label="业务消息主键">
          <el-input v-model="dataForm.bizId" placeholder="业务消息主键" clearable></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="业务类型编码">
          <el-input v-model="dataForm.bizTypeCode" placeholder="业务类型编码" clearable></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="发送状态">
          <el-select v-model="dataForm.bizSendStatus" placeholder="发送状态" clearable>
            <el-option label="未发送" :value="0"></el-option>
            <el-option label="发送中" :value="1"></el-option>
            <el-option label="成功" :value="2"></el-option>
            <el-option label="失败" :value="3"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
    </uni-list-query-card>
    <el-card shadow="never" class="aui-card-list-body">
      <vxe-toolbar :setting="{immediate:true}">
        <template v-slot:buttons>
          <el-button v-if="$hasPermission('msg:msgBizInfo:save')" type="primary" @click="addOrUpdateHandle()">
            {{ $t('add') }}</el-button>
          <el-button v-if="$hasPermission('msg:msgBizInfo:delete')" type="danger" @click="deleteHandle()">
            {{ $t('deleteBatch') }}</el-button>
        </template>
        <template v-slot:tools>
          <el-button icon="el-icon-search" @click="searchShowHandle()" circle></el-button>
          <el-button icon="el-icon-refresh" @click="getDataList()" circle></el-button>
        </template>
      </vxe-toolbar>
      <vxe-table ref="xTable" :loading="dataListLoading" class="vxe-table-element" auto-resize @select-change="dataListSelectionChangeHandleVex"
        @select-all="dataListSelectionAllChangeHandleVex" :data="dataList">
        <vxe-table-column type="checkbox" align="center" width="60"></vxe-table-column>
        <vxe-table-column field="bizId" title="业务消息主键" width="180">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row)">{{scope.row.bizId}}</el-button>
          </template>
        </vxe-table-column>
        <vxe-table-column field="bizTypeCode" title="业务规则">
          <template slot-scope="scope">
            {{ assBizTypeCode(scope.row) }}
          </template>
        </vxe-table-column>
        <vxe-table-column field="bizCreateTime" title="创建时间" width="140">
        </vxe-table-column>
        <vxe-table-column field="bizSendStatus" title="发送状态" width="100">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.bizSendStatus===0" size="small" type="info">未发送</el-tag>
            <el-tag v-if="scope.row.bizSendStatus===1" size="small" type="info">发送中</el-tag>
            <el-tag v-if="scope.row.bizSendStatus===2" size="small" type="success">成功</el-tag>
            <el-tag v-if="scope.row.bizSendStatus===3" size="small" type="danger">失败</el-tag>
          </template>
        </vxe-table-column>
        <vxe-table-column field="bizSendTime" title="发送时间" width="140">
        </vxe-table-column>
        <vxe-table-column field="bizSendRetry" title="失败次数" width="80">
        </vxe-table-column>
      </vxe-table>
      <el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total" layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle" @current-change="pageCurrentChangeHandle">
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->

    </el-card>
  </div>
</template>
<script>
import mixinViewModule from '@/mixins/view-module'

export default {
  mixins: [mixinViewModule],
  data () {
    return {
      searchShow: true,
      mixinViewModuleOptions: {
        getDataListURL: '/msg/msgBizInfo/page',
        getDataListIsPage: true,
        deleteURL: '/msg/msgBizInfo',
        deleteIsBatch: true,
        exportURL: '/msg/msgBizInfo/export'
      },
      ruleList: [],
      dataForm: {
        bizId: '',
        bizTypeCode: '',
        bizSendStatus: ''
      }
    }
  },
  components: {
  },
  created () {
    this.loadRuleList()
  },
  methods: {
    assBizTypeCode (row) {
      let rule = this.$getDataItem(this.ruleList, row.bizTypeCode, 'id')
      let text = rule.eventName === rule.title ? rule.eventName : rule.eventName + '-' + rule.title
      text = text + '(' + row.bizTypeCode + ')'
      return text
    },
    loadRuleList () {
      this.$http.get('msg/msgBizRule/list').then(({ data: res }) => {
        if (res.code === 0) {
          this.ruleList = res.data
        }
      })
    },
    // 新增 / 修改
    addOrUpdateHandle (row) {
      let id
      if (row) {
        id = row.id
      }
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.dataForm.id = id
        this.$refs.addOrUpdate.init()
      })
    }
  }
}
</script>
